package com.tianji.promotion.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.promotion.domain.dto.CouponDiscountDTO;
import com.tianji.promotion.domain.dto.OrderCouponDTO;
import com.tianji.promotion.domain.dto.OrderCourseDTO;
import com.tianji.promotion.domain.query.CouponQuery;
import com.tianji.promotion.domain.vo.CouponVO;
import com.tianji.promotion.domain.vo.OrderCouponDetail;
import com.tianji.promotion.service.IUserCouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 用户领取优惠券的记录，是真正使用的优惠券信息 前端控制器
 * </p>
 *
 * @author yb0os1
 * @since 2025-03-09
 */
@Api("用户领取优惠券的相关接口")
@RestController
@RequestMapping("/user-coupons")
@RequiredArgsConstructor
public class UserCouponController {
    private final IUserCouponService userCouponService;
    @ApiOperation("领取优惠券")
    @PostMapping("/{couponId}/receive")
    public void receiveCoupon(@PathVariable Long couponId) {
        userCouponService.receiveCoupon(couponId);
    }

    @ApiOperation("兑换码兑换优惠券")
    @PostMapping("/{code}/exchange")
    public void codeExchangeCoupon(@PathVariable String code) {
        userCouponService.codeExchangeCoupon(code);
    }

    @ApiOperation("查询我的优惠券")
    @GetMapping("/page")
    public PageDTO<CouponVO> queryMyCoupons(CouponQuery query) {
        return userCouponService.queryMyCoupons(query);
    }

    @ApiOperation("查询可用优惠券方案")
    @PostMapping("/available")
    public List<CouponDiscountDTO> findDiscountSolution(@RequestBody List<OrderCourseDTO> orderCourses) {
        return userCouponService.findDiscountSolution(orderCourses);
    }

    @ApiOperation("根据券的方案计算订单优惠明细")
    @PostMapping("/discount")
    public CouponDiscountDTO orderCouponDetail(@RequestBody OrderCouponDTO dto) {
        return userCouponService.getOrderCouponDetail(dto);
    }

    @ApiOperation("核销优惠券")
    @PutMapping("/use")
    public void useCoupon(@RequestParam List<Long> couponIds){
        userCouponService.writeOffCoupon(couponIds);
    }

    @ApiOperation("退款优惠券")
    @PutMapping("/refund")
    public void refundCoupon(@RequestParam List<Long> couponIds){
        userCouponService.refundCoupon(couponIds);
    }

    @ApiOperation("查询优惠券使用规则")
    @GetMapping("/rules")
    public List<String> queryCouponRules(@RequestParam List<Long> couponIds){
        return userCouponService.queryCouponRules(couponIds);
    }
}
